<?php

declare(strict_types=1);

namespace App\CustHub\Listener;

use App\CustHub\Event\AutoKickTrigger;
use App\CustHub\Service\ChRoomKickUserService;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Psr\Container\ContainerInterface;

/**
 * 自动踢人
 */
#[Listener]
class AutoKickListener implements ListenerInterface
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * @return string[] returns the events that you want to listen
     */
    public function listen(): array
    {
        return [AutoKickTrigger::class];
    }

    public function process(object $event): void
    {
        stdout_log()->info('自动踢人'.json_encode($event));
        $service = $this->container->get(ChRoomKickUserService::class);
        if($event->type){
            $service->handlePendingKick($event->robot,$event->data);
        }else{
            $service->triggerHandler($event->robot,$event->data);
        }
    }
}